We first need to install R
We can do that by going to: https://cran.r-project.org
Choose the version of R that corresponds to your OS (operating system)
Choose the version of R that corresponds to your OS (operating system)
We then need to install R Studio
We can do that by going to: https://posit.co/download/rstudio-desktop/
We then need to install R Studio
We can do that by going to: https://posit.co/download/rstudio-desktop/
Install the version of RStudio relevant for your OS
We then need to install R Studio
We can do that by going to: https://posit.co/download/rstudio-desktop/
Install the version of RStudio relevant for your OS
To keep track of the operation that we perform in R, we should save them in scripts
To create a new code file, we can select File -> New File -> R script from the menu or by pressing Ctrl+Shift+N or Cmd+Shift+N
The new file or a modified existing file can be saved using Ctrl+S or Cmd+S
In this course, we will work with Quarto files
Quarto is a version of R Markdown from RStudio that allows us to run code and write text.
Code blocks that use braces around the language name (e.g. ```{r}) are executable, and will be run by Quarto during render.
Quarto files have the *.qmd extension
Quarto files have the following code in their preamble (start of the page)
Note that the indentation matters
For example, we have the following code:
---
title: "ggplot2 demo"
author: "Norah Jones"
date: "12/19/2023"
format:
html:
code-fold: true
---
## Air Quality
@fig-airquality further explores the impact of temperature on ozone level.
```{r}
#| label: fig-airquality
#| fig-cap: "Temperature and ozone level."
#| warning: false
library(ggplot2)
ggplot(airquality, aes(Temp, Ozone)) +
geom_point() +
geom_smooth(method = "loess")
```Would produce the following output
This is what the files look like on a macbook after rendering them.
You can produce a wide variety of output types:
You can render quarto documents by pressing the render button
You can render quarto documents by pressing the render button
You can render quarto documents by pressing the render button
You should render your files on regular basis to identify and fix errors early on.
To use Quarto with R, you should install the rmarkdown R package:
Use the File : New File : Quarto Document… command to create new Quarto documents
You can easily include a new code chunk by clicking the green “c” button
You can easily include a new code chunk by clicking the green “c” button
You can create Quarto Notebooks and presentations easily.
You simply need to change the preamble.
This is for example the preamble for course syllabus
This is the output:
This is for example the preamble for the the presentation for today.
---
title: "L2: Introduction to R, Quarto, and R evironments"
author:
name: Bogdan G. Popescu
email: bogdan.popescu@johncabot.edu
affiliations: John Cabot University
format:
revealjs:
slide-number: c/t
show-slide-number: all
preview-links: auto
width: 1050
height: 700
fontsize: 24pt
footer: "Popescu (JCU): Lecture 2"
sansfont: Latin Modern Roman
embed-resources: true
---
# Slide 1
This is an example
# Slide 2
This is another exampleThis is the output for slide 1
This is the output for slide 2
This is the output for slide 3
The platform interface for R studio looks like below:
The platform interface for R studio looks like below:
The platform interface for R studio looks like below:
The platform interface for R studio looks like below:
The platform interface for R studio looks like below:
Let us now use R to understand how it works.
Let’s create a new quarto document and save it in your “week2” folder